// ========================================================
// clipAreaEx Example
// make : pwg
// date : 2003
// note : 클립영역으로 처리한 Frame과 클립영역으로 처리하지 않은
//           Frame 비교.(nonClipAreaEx.class참조)
// ========================================================
package j_graphics;

import java.awt.*;
import java.awt.event.*;

public class  ClipAreaEx extends Frame implements WindowListener
{
	static int window_cnt=0; // 창의 갯수(갯수=0이면 프로그램 종료)
	
	public ClipAreaEx(String title)
	{
		setTitle(title);
		addWindowListener(this);
		window_cnt ++;
	}

	public void painting()
	{
		Graphics g=getGraphics();
		Rectangle a=new Rectangle(50,50,100,100);
		Rectangle r=g.getClipBounds(a);
		

	}

	public void paint(Graphics g)
	{
		Rectangle r=g.getClipBounds();

		System.out.println(r.x );
		System.out.println(r.y );
		System.out.println(r.width );
		System.out.println(r.height);
		System.out.println("----------");

		g.clipRect(r.x, r.y, r.width, r.height);
		g.setClip(r.x, r.y, r.width, r.height);
		int px=0, py=0;
		

		for(py=0 ; py<200 ; py++)
		{
			for(px=0 ; px<200; px++)
			{
				g.setColor(new Color(px,py,100));
				g.drawRect(px,py, 1,1);
			}
		}
	}


	public static void main(String[] args) 
	{
		ClipAreaEx f1=new ClipAreaEx("Clipping");

		f1.setBounds(50,0,300,300);

		f1.setVisible(true);

	}

	public void windowClosing(WindowEvent e) 
	{
		window_cnt --;
		dispose();
	}
	public void windowOpened(WindowEvent e) {   }
	public void windowClosed(WindowEvent e) 
	{
		if(window_cnt ==0) System.exit(0);
	}
	public void windowActivated(WindowEvent e) {   }
	public void windowDeactivated(WindowEvent e) {   }
	public void windowIconified(WindowEvent e) {   }
	public void windowDeiconified(WindowEvent e) {   }



/*	//WindowAdpater
	class myWindowAdapter extends WindowAdapter
	{
		public void windowClosing(WindowEvent e)
		{
			if(e.getWindow()==f1) f1.dispose();
			if(e.getWindow()==f2) f2.dispose();

		}
	};

*/
}
